#include "widget.h"
#include "ui_widget.h"
#include <QTabWidget>
#include <QTableWidget>
#include <QPushButton>
#include <QVBoxLayout>
#include <QGridLayout>
#include <QFormLayout>
#include <QLabel>
#include <QLineEdit>

//Widget::Widget(QWidget *parent)
//    : QWidget(parent)
//    , ui(new Ui::Widget)
//{
//    ui->setupUi(this);
//    QPushButton* btn1 = new QPushButton("按钮1");
//    QPushButton* btn2 = new QPushButton("按钮2");

//    QHBoxLayout* hlayout = new QHBoxLayout(this);
//    hlayout->addWidget(btn1);
//    QSpacerItem* space = new QSpacerItem(200,5);
//    hlayout->addSpacerItem(space);
//    hlayout->addWidget(btn2);
//}

//Widget::Widget(QWidget *parent)
//    : QWidget(parent)
//    , ui(new Ui::Widget)
//{
//    ui->setupUi(this);
//    QFormLayout* form = new QFormLayout();
//    this->setLayout(form);
//    QLabel* label1 = new QLabel("姓名");
//    QLabel* label2 = new QLabel("年龄");
//    QLabel* label3 = new QLabel("电话");

//    QLineEdit* lineEdit1 = new QLineEdit();
//    QLineEdit* lineEdit2 = new QLineEdit();
//    QLineEdit* lineEdit3 = new QLineEdit();

//    QPushButton* btn = new QPushButton("提交");

//    form->addRow(label1,lineEdit1);
//    form->addRow(label2,lineEdit2);
//    form->addRow(label3,lineEdit3);
//    form->addRow(nullptr,btn);
//}

//Widget::Widget(QWidget *parent)
//    : QWidget(parent)
//    , ui(new Ui::Widget)
//{
//    ui->setupUi(this);
//    QPushButton* btn1 = new QPushButton("按钮1");
//    QPushButton* btn2 = new QPushButton("按钮2");
//    QPushButton* btn3 = new QPushButton("按钮3");
//    QPushButton* btn4 = new QPushButton("按钮4");
//    QPushButton* btn5 = new QPushButton("按钮5");
//    QPushButton* btn6 = new QPushButton("按钮6");

//    //设置水平与垂直方向上的sizePolicy
//    btn1->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
//    btn2->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
//    btn4->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);

//    QGridLayout* gridLayout = new QGridLayout(this);
//    gridLayout->addWidget(btn1,0,0);
//    gridLayout->addWidget(btn2,0,1);
//    gridLayout->addWidget(btn3,0,2);
//    gridLayout->addWidget(btn4,1,0);
//    gridLayout->addWidget(btn5,1,1);
//    gridLayout->addWidget(btn6,1,2);

//    //设置拉伸系数
//    // 第 0 列拉伸⽐例设为 1
//    gridLayout->setRowStretch(0,1);
//    //第2列跨度是第0列的3倍
//    gridLayout->setRowStretch(1,3);

//}

//Widget::Widget(QWidget *parent)
//    : QWidget(parent)
//    , ui(new Ui::Widget)
//{
//    ui->setupUi(this);
//    //创建顶层布局
//    QVBoxLayout* VlayoutParent = new QVBoxLayout();
//    this->setLayout(VlayoutParent);

//    QPushButton* btn1 = new QPushButton("按钮1");
//    QPushButton* btn2 = new QPushButton("按钮2");
//    VlayoutParent->addWidget(btn1);
//    VlayoutParent->addWidget(btn2);

//    QPushButton* btn3 = new QPushButton("按钮3");
//    QPushButton* btn4 = new QPushButton("按钮4");

//    QHBoxLayout* HlayoutChild = new QHBoxLayout(this);
//    HlayoutChild->addWidget(btn3);
//    HlayoutChild->addWidget(btn4);
//    //这个⼦ layout 添加到 ⽗ layout 中
//    VlayoutParent->addLayout(HlayoutChild);
//}

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    QPushButton* btn1 = new QPushButton("按钮1",this);
    QPushButton* btn2 = new QPushButton("按钮2",this);
    QPushButton* btn3 = new QPushButton("按钮3",this);

    QHBoxLayout* Hlayout = new QHBoxLayout(this);
    Hlayout->addWidget(btn1);
    Hlayout->addWidget(btn2);
    Hlayout->addWidget(btn3);
    Hlayout->setSpacing(100);   //相邻元素之间的间隔
}

//Widget::Widget(QWidget *parent)
//    : QWidget(parent)
//    , ui(new Ui::Widget)
//{
//    ui->setupUi(this);
////    ui->groupBox->setTitle("肉类");
////    ui->groupBox->setCheckable(true);
////    ui->groupBox_2->setCheckable(true);
//}

//Widget::Widget(QWidget *parent)
//    : QWidget(parent)
//    , ui(new Ui::Widget)
//{
////    ui->setupUi(this);
////    //使标签页位于左下角
////    ui->tabWidget->setTabPosition(QTabWidget::South);
////    //标签页可以关闭
////    ui->tabWidget->setTabsClosable(true);
////    //标签页可以移动
////    ui->tabWidget->setMovable(true);
////    //向当前标签页中设置内容
////    QWidget* curWidget = ui->tabWidget->currentWidget();
////    //将TableWidget的父对象设置为标签页
////    QTableWidget* tableWidget = new QTableWidget(curWidget);

////    tableWidget->setGeometry(curWidget->x(),curWidget->y(),500,300);
////    tableWidget->setRowCount(3);
////    tableWidget->setColumnCount(3);
////    tableWidget->setItem(0,0,new QTableWidgetItem(QString("C++")));
////    tableWidget->setItem(1,1,new QTableWidgetItem(QString("Java")));
////    tableWidget->setItem(2,2,new QTableWidgetItem(QString("Qt")));

//    //向当前标签页中添加一个TableWidget
////    QWidget* widget = new QWidget(this);
////    ui->tabWidget->addTab(widget,QString("sheet3"));
//}

Widget::~Widget()
{
    delete ui;
}

//void Widget::on_pushButton_clicked()
//{
//    int curIndex = ui->tabWidget->count();
//    QWidget* newWidget = new QWidget();
//    ui->tabWidget->addTab(newWidget,QString("sheet") + QString::number(curIndex + 1));
//    //选中新增标签页
//    ui->tabWidget->setCurrentIndex(curIndex);
//}

//void Widget::on_pushButton_2_clicked()
//{
//    int curIndex = ui->tabWidget->currentIndex();
//    ui->tabWidget->removeTab(curIndex); //删除当前标签页
//}

//void Widget::on_tabWidget_tabCloseRequested(int index)
//{
//    //设置关闭按钮的槽函数
//    ui->tabWidget->removeTab(index);
//}
